<?php

// 本类由系统自动生成，仅供测试用途
class IndexAction extends Action {

    public function index() {
        $this->display();
    }

    public function ckuser() {
        $name = htmlspecialchars($_GET['name']);
        $User = M('User');
        //开始判断用户是否存在
        $return_user = $User->where(array("name" => $name))->find();
        
        if (empty($return_user)) {
                echo "1";
        }  else {
          echo "-3";
        } 
    }
   
         public function ckemail() {
        $email = htmlspecialchars($_GET['email']);
        $User = M('User');
        //开始判断用户是否存在
        $return_user = $User->where(array("email" => $email))->find();
        
        if (empty($return_user)) {
                echo "1";
        }  else {
          echo "-6";
        } 
    }
    

    public function checklogin() {
        $account = htmlspecialchars($_POST['account']);
        $password = htmlspecialchars($_POST['password']);
        $email = htmlspecialchars($_POST['email']);
        $nicname = htmlspecialchars($_POST['nicname']);
        $imgurl = htmlspecialchars($_POST['imgurl']);
        $telno = htmlspecialchars($_POST['telno']);

         if(empty($password)){            $this->error("注册密码不能为空！");
                        return;}
         if(empty($account)){            $this->error("注册用户不能为空！");
                        return;}
                        
          //实例化用户数据数据表
        $User = M('User');
        //开始判断用户是否存在
        $return_user = $User->where(array("name" => $account))->find();
        
        if (empty($return_user)) {
        import('ORG.Net.UploadFile');
        $upload = new UploadFile(); // 实例化上传类
        $upload->maxSize = 3145728; // 设置附件上传大小
        $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型
        $upload->savePath = './Public/Uploads/Userimg/'; // 设置附件上传目录
        $upload->saveRule = "time";      //设置文件上传名(按照时间) 
        $upload->autoSub = true;
        $upload->subType = "date";
        $upload->thumb = true;
        $upload->thumbMaxWidth = '400,200'; //设置两个图
        $upload->thumbMaxHeight = '400,200';
        $upload->thumbPrefix = "m_,s_";

        if (!$upload->upload()) {// 上传错误提示错误信息
            $this->error($upload->getErrorMsg());
            return;
        } else {// 上传成功 获取上传文件信息
            $info = $upload->getUploadFileInfo();
              
        }
            $salt = rand(1000, 9999);
            $arr = array(
                "sex" => "2",
                "name" => $account,
                "domain" => _toPinyin($nicname),
                "nick" => $nicname,
                "password" => md5(md5($password) . $salt),
                "salt" => $salt,
                "phone" => $telno,
                "email" => $email,
                "avatar" =>  str_zwbth(".", $info[0]['savepath'])."/".$info[0]['savename'],
                "departId" => "1",
                "status" => "0",
                "created" => time(),
                "mimg"=>str_zwbth(".", $info[0]['savepath'])."/m_".$info[0]['savename'],
                "simg"=>str_zwbth(".", $info[0]['savepath'])."/s_".$info[0]['savename'],
            );
            $return_users = $User->add($arr);

            if ($return_users !== FALSE) {
                $this->success("注册成功",U('Home/index'));
            } else {
                $this->error("写入数据库失败");
                return;
            }
        } else {
            //  echo _tojson(1, $departName . "已存在", null);
            $this->error($departName . "已存在，请重新输入登录账户");
            return;
        }

        //参数：sex,name,nick,password,phone,email,avatar,departId,sign(性别，登录名，昵称，密码，手机号码，邮箱，图像地址，部门ID,签名)
         } 

}
